// Copyright (C) 2025, ZWSOFT Co., LTD.(Guangzhou)
// Licensed under the MIT License. See LICENSE in the project root for license information.

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using TestClient.Domain;

namespace TestClient.ViewModel;

public partial class PlaneSelectionItem : ObservableObject
{
    public PlaneSelectionItem(int id, string name)
    {
        Id = id;
        Name = name;
    }

    public int Id { get; }

    [ObservableProperty]
    private string name;

    [ObservableProperty]
    private bool isSelected;
}

public partial class SketchTestViewModel : PageViewModelBase
{
    [ObservableProperty]
    private int selectedPlane;

    [ObservableProperty]
    private string sketchName = "";

    public ObservableCollection<PlaneSelectionItem> Planes { get; } =
    [
        new(0, "XY"),
        new(1, "YZ"),
        new(2, "XZ"),
    ];

    public IAsyncRelayCommand CreateSplineCommand { get; }

    public SketchTestViewModel(ISnackNotifyService notifyService, VFAdapterWrapper wrapper) : base(wrapper, notifyService)
    {
        CreateSplineCommand = CreateAsyncRpcCommand(CreateSpline);
    }

    private async Task CreateSpline()
    {
        EnsureConnected();
        var selected = Planes.Where(x => x.IsSelected).Select(x => x.Id).First();

        await Task.Run(() =>
        {
            Wrapper.CreateSpline2d(SketchName, selected, testSpline);
        });
    }

    private static readonly Vector2d[] testSpline = [
        new(369.503,-772.573),
        new(340.294,-772.573),
        new(311.234,-772.573),
        new(282.031,-772.573),
        new(252.967,-772.573),
        new(223.767,-772.573),
        new(194.701,-772.573),
        new(165.502,-772.573),
        new(136.437,-772.573),
        new(107.236,-772.573),
        new(41.8547,-772.583),
        new(49.0148,-772.583),
        new(19.8844,-772.583),
        new(-9.24609,-772.583),
        new(-38.3765,-772.583),
        new(-52.4926,-772.583),
        new(-96.6158,-772.573),
        new(-125.854,-772.573),
        new(-154.878,-772.573),
        new(-184.152,-772.573),
        new(-213.141,-772.573),
        new(-242.5,-772.573),
        new(-271.403,-772.573),
        new(-301.145,-772.573),
        new(-301.145,-772.573),
        new(-301.116,-771.617),
        new(-301.116,-771.617),
        new(-300.628,-741.858),
        new(-300.554,-727.906),
        new(-300.55,-682.326),
        new(-300.55,-652.559),
        new(-300.55,-622.794),
        new(-300.55,-593.026),
        new(-300.55,-563.259),
        new(-300.55,-533.494),
        new(-300.55,-503.727),
        new(-300.55,-473.959),
        new(-300.55,-444.192),
        new(-300.55,-414.426),
        new(-300.55,-384.66),
        new(-300.55,-354.892),
        new(-300.55,-325.126),
        new(-300.55,-295.358),
        new(-300.55,-265.592),
        new(-300.55,-235.826),
        new(-300.55,-206.059),
        new(-300.55,-176.292),
        new(-300.55,-146.525),
        new(-300.55,-116.758),
        new(-300.57,-33.0089),
        new(-300.551,-57.225),
        new(-300.752,-27.4622),
        new(-301.276,2.32121),
        new(-300.691,32.0789),
        new(-300.551,58.1576),
        new(-300.55,91.6093),
        new(-300.55,121.376),
        new(-300.55,151.143),
        new(-300.55,180.91),
        new(-300.55,210.677),
        new(-300.55,240.443),
        new(-300.55,270.209),
        new(-300.55,299.976),
        new(-300.55,329.743),
        new(-300.55,359.511),
        new(-300.55,389.277),
        new(-300.55,419.043),
        new(-300.55,448.81),
        new(-300.55,478.578),
        new(-300.55,508.345),
        new(-300.55,538.11),
        new(-300.55,567.876),
        new(-300.55,597.645),
        new(-300.55,627.41),
        new(-300.55,657.177),
        new(-300.55,686.945),
        new(-300.551,723.289),
        new(-300.671,746.474),
        new(-300.671,746.474),
        new(-300.685,747.431),
        new(-300.685,747.431),
        new(-271.417,747.431),
        new(-242.326,747.431),
        new(-213.156,747.431),
        new(-184.049,747.431),
        new(-154.895,747.431),
        new(-125.782,747.431),
        new(-96.6338,747.431),
        new(-52.4926,747.434),
        new(-38.3765,747.434),
        new(-9.24609,747.434),
        new(19.8844,747.434),
        new(49.0148,747.434),
        new(41.8547,747.434),
        new(107.269,747.431),
        new(136.412,747.431),
        new(165.531,747.431),
        new(194.672,747.431),
        new(223.792,747.431),
        new(252.934,747.431),
        new(282.054,747.431),
        new(311.196,747.431),
        new(340.315,747.431),
        new(369.458,747.431),
        new(369.458,747.431),
        new(369.457,746.474),
        new(369.457,746.474),
        new(369.45,723.289),
        new(369.45,686.945),
        new(369.45,657.177),
        new(369.45,627.41),
        new(369.45,597.645),
        new(369.45,567.876),
        new(369.45,538.11),
        new(369.45,508.345),
        new(369.45,478.578),
        new(369.45,448.81),
        new(369.45,419.043),
        new(369.45,389.277),
        new(369.45,359.511),
        new(369.45,329.743),
        new(369.45,299.976),
        new(369.45,270.209),
        new(369.45,240.443),
        new(369.45,210.677),
        new(369.45,180.91),
        new(369.45,151.143),
        new(369.45,121.376),
        new(369.45,91.6093),
        new(369.45,58.1576),
        new(369.459,32.0789),
        new(369.519,2.32121),
        new(369.463,-27.4622),
        new(369.45,-57.225),
        new(369.451,-33.0089),
        new(369.45,-116.758),
        new(369.45,-146.525),
        new(369.45,-176.292),
        new(369.45,-206.059),
        new(369.45,-235.826),
        new(369.45,-265.592),
        new(369.45,-295.358),
        new(369.45,-325.126),
        new(369.45,-354.892),
        new(369.45,-384.66),
        new(369.45,-414.426),
        new(369.45,-444.192),
        new(369.45,-473.959),
        new(369.45,-503.727),
        new(369.45,-533.494),
        new(369.45,-563.259),
        new(369.45,-593.026),
        new(369.45,-622.794),
        new(369.45,-652.559),
        new(369.45,-682.326),
        new(369.45,-727.906),
        new(369.454,-741.858),
        new(369.499,-771.617),
        new(369.499,-771.617),
        new(369.503,-772.573),
        ];
}
